<template>
	<view>
		<u-card padding="16">
			<view class="" slot="head">
				<view class="wrap">
					<u-row>
						<u-col span="12" text-align="center" v-if="HxStoragePutDetailedParam.photofile">
							<view style="height: 400rpx;" class="u-line-1 u-m-t-10"
								@click="viewImage(HxStoragePutDetailedParam.photofile)">
								<u-image width="450rpx" height="400rpx"
									:src="imgs(HxStoragePutDetailedParam.photofile)"></u-image>
							</view>
						</u-col>
					</u-row>
					<u-row>
						<u-col span="12">
							<view class="u-m-t-5 weikaishi3 lanse">
								<span>
									<span v-if="isNewProduct" class="new-product">新品</span>
									<u-icon name="coupon" size="30" labelSize="15px" labelColor="#000000"></u-icon>
									{{ HxStoragePutDetailedParam.goodsName }}
								</span>
							</view>
						</u-col>
					</u-row>
					<u-row>
						<u-col span="12">
							<view class="weikaishi3">
								<span>
									<u-icon name="coupon" size="29" labelSize="14px" labelColor="#000000" label="商品码"
										color="#000000"></u-icon>：{{HxStoragePutDetailedParam.goodsPcode69}}
								</span>
							</view>
						</u-col>
					</u-row>
					<u-row>
						<u-col span="12">
							<view class="weikaishi3">
								<span>
									<u-icon name="coupon" size="29" labelSize="14px" labelColor="#000000" label="商品编号">
									</u-icon>：{{HxStoragePutDetailedParam.goodsNumber}}
								</span>
							</view>
						</u-col>
					</u-row>
					<u-row v-if="HxStoragePutDetailedParam.dismantlingParts == '是'">
						<u-col span="12">
							<view class="weikaishi3 yizuofei">
								<span>
									<u-icon name="coupon" size="29" labelSize="14px" labelColor="#000000">
									</u-icon>拆零：{{HxStoragePutDetailedParam.dismantlingParts}}
								</span>
							</view>
						</u-col>
					</u-row>
					<u-row>
						<u-col span="12">
							<view class="weikaishi3">
								<span>
									<u-icon name="coupon" size="29" labelSize="14px" labelColor="#000000" label="规格">
									</u-icon>：{{HxStoragePutDetailedParam.goodsSpecs}}
								</span>
							</view>
						</u-col>
					</u-row>
					<u-row>
						<u-col span="7">
							<view class="weikaishi6">
								<span>
									<u-icon name="clock" size="29" labelSize="14px" labelColor="#000000" label="数量"
										color="#000000"></u-icon>
									：{{HxStoragePutDetailedParam.num}}{{HxStoragePutDetailedParam.unit}}/{{HxStoragePutDetailedParam.putVolume}}方
								</span>
							</view>
						</u-col>
						<u-col span="5" v-if="HxStoragePutDetailedParam.num == HxStoragePutDetailedParam.realNum">
							<view class="weikaishi6 yiwancheng">
								<span>
									<u-icon name="checkmark-circle" size="29" labelSize="14px" labelColor="#00c300"
										label="实入" color="#00c300"></u-icon>：{{HxStoragePutDetailedParam.realNum}}
								</span>
							</view>
						</u-col>
						<u-col span="5" v-else>
							<view class="weikaishi6">
								<span>
									<u-icon name="checkmark-circle" size="29" labelSize="14px" labelColor="#000000"
										label="实入" color="#000000"></u-icon>：{{HxStoragePutDetailedParam.realNum}}
								</span>
							</view>
						</u-col>
					</u-row>
					<u-row>
						<u-col span="12" text-align="left">
							<u-checkbox v-model="printChecked">是否打印</u-checkbox>
						</u-col>
					</u-row>
					<u-row>
						<u-col span="6" text-align="center"
							v-if="HxStoragePutDetailedParam.realNum == null || HxStoragePutDetailedParam.realNum == '' || HxStoragePutDetailedParam.realNum <= 0">
							<u-button type="default" size="medium" @click="editGoods(HxStoragePutDetailedParam)">规则属性
							</u-button>
						</u-col>
						<u-col span="6" text-align="center">
							<u-button type="primary" size="medium" @click="allQuality(HxStoragePutDetailedParam)">全部质检
							</u-button>
						</u-col>
					</u-row>
				</view>
			</view>
			<view class="" slot="body">
				<view class="wrap">
					<u-row>
						<u-col span="3" text-align="center">
							<view class=" u-m-t-4 weikaishi">
								<span>托号</span>
							</view>
						</u-col>
						<u-col span="2" text-align="center">
							<view class=" u-m-t-4 weikaishi">
								<span>应入</span>
							</view>
						</u-col>
						<u-col span="2" text-align="center">
							<view class=" u-m-t-4 weikaishi">
								<span>实入</span>
							</view>
						</u-col>
						<u-col span="2" text-align="center">
							<view class=" u-m-t-4 weikaishi">
								<span>库位</span>
							</view>
						</u-col>
						<u-col span="3" text-align="center">
							<view class=" u-m-t-4 weikaishi">
								<span>生产日期</span>
							</view>
						</u-col>
					</u-row>
					<u-row v-for="(item,index) in dataList" :key="index" @click="quality(item)">
						<u-col span="3" text-align="center" v-if="item.putState == '待质检'">
							<view class="weikaishi lanse u-m-t-25 huanhang">
								<span>{{item.trayNumber}}</span>
							</view>
						</u-col>
						<u-col span="3" text-align="center" v-else>
							<view class="weikaishi yiwancheng u-m-t-25 huanhang">
								<span>{{item.trayNumber}}</span>
							</view>
						</u-col>
						<u-col span="2" text-align="center">
							<view class="weikaishi u-m-t-25 huanhang">
								<span>{{item.num}}</span>
							</view>
						</u-col>
						<u-col span="2" text-align="center">
							<view class="weikaishi u-m-t-25 huanhang">
								<span>{{item.realNum}}</span>
							</view>
						</u-col>
						<u-col span="2" text-align="center">
							<view class="weikaishi u-m-t-25 huanhang">
								<span>{{item.positionNumber}}</span>
							</view>
						</u-col>
						<u-col span="3" text-align="center">
							<view class="weikaishi u-m-t-25 huanhang">
								<span>{{item.detailedDate}}</span>
							</view>
						</u-col>
						<u-col span="12" text-align="center">
							<view class="jiange">
							</view>
						</u-col>
					</u-row>
				</view>
			</view>
		</u-card>
		<view style="height: 40rpx;">
		</view>
		<view class="wrap" style="position: fixed;bottom: 0rpx;width: 100%;background-color: #f0f0f0;z-index: 999;">
			<u-row>
				<u-col span="12" text-align="center">
					<u-icon name="plus" color="#2b85e4" size="45" @click="toadd()"></u-icon>
				</u-col>
			</u-row>
		</view>
		<view>
			<u-toast ref="uToast" />
		</view>
		<u-popup v-model="popupShow" mode="center" closeable width="500rpx" height="400rpx" border-radius="10">
			<view class="u-text-center u-m-t-20">质检{{fromd.trayNumber}}</view>
			<view class=" u-m-20">
				<u-input v-model="fromd.realNum" type="digit" :border="true" placeholder="请输入实入数" />
			</view>
			<view class=" u-m-20">
				<u-input v-model="fromd.detailedDate" type="select" @click="getT()" placeholder="选择生产日期"
					:border="true" />
			</view>
			<view style="height: 80rpx;text-align: center;">
				<view class="close-btn u-m-t-40">
					<u-button size="medium" type="error" @click="deletet()">删除</u-button>
					<u-button size="medium" @click="define()">确定</u-button>
				</view>
			</view>
		</u-popup>
		<u-popup v-model="popupShow2" mode="center" closeable width="700rpx" height="850rpx" border-radius="10">
			<view class="u-text-center u-m-t-20">按采购单位：{{fromgz.unit}}进行设置</view>
			<view class=" u-m-20">
				<span>底：</span>
				<u-input v-model="fromgz.goodsBottom" type="digit" :border="true" placeholder="底" />
			</view>
			<view class=" u-m-20">
				<span>叠层：</span>
				<u-input v-model="fromgz.goodsLamination" type="digit" :border="true" placeholder="叠层" />
			</view>
			<view class=" u-m-20">
				<span>体积m³：</span>
				<u-input v-model="fromgz.goodsVolume" type="digit" :border="true" placeholder="单件体积" />
			</view>
			<view class=" u-m-20">
				<span>重量：</span>
				<u-input v-model="fromgz.goodsWeight" type="digit" :border="true" placeholder="单件重量" />
			</view>
			<view class=" u-m-20">
				<span>商品码：</span>
				<u-input v-model="fromgz.goodsPcode69" type="digit" :border="true" placeholder="商品码" disabled />
			</view>
			<view class=" u-m-20">
				<span>商品码2：</span>
				<u-input v-model="fromgz.goodsXcode69" type="digit" :border="true" placeholder="商品码2" />
			</view>
			<view class=" u-m-20">
				<span>商品码3：</span>
				<u-input v-model="fromgz.goodsHcode69" type="digit" :border="true" placeholder="商品码3" />
			</view>
			<view style="height: 80rpx;text-align: center;">
				<view class="close-btn u-m-t-40">
					<u-button size="medium" @click="define2()">确定</u-button>
				</view>
			</view>
		</u-popup>
		<u-popup v-model="popupShow3" mode="center" closeable width="500rpx" height="350rpx" border-radius="10">
			<view class="u-text-center u-m-t-20">全部质检</view>
			<view class=" u-m-20">
				<u-input v-model="frombatch.detailedDate" type="select" @click="getT3()" placeholder="选择生产日期"
					:border="true" />
			</view>
			<view style="height: 80rpx;text-align: center;">
				<view class="close-btn u-m-t-40">
					<u-button size="medium" @click="define3()">确定</u-button>
				</view>
			</view>
		</u-popup>
		<u-popup v-model="popupShow4" mode="center" closeable width="500rpx" height="350rpx" border-radius="10">
			<view class="u-text-center u-m-t-20">新增</view>
			<view class=" u-m-20">
				<u-input v-model="addNum" type="digit" :border="true" placeholder="请输入数量" />
			</view>
			<view style="height: 80rpx;text-align: center;">
				<view class="close-btn u-m-t-40">
					<u-button size="medium" @click="define4()">确定</u-button>
				</view>
			</view>
		</u-popup>
		<view>
			<u-calendar v-model="show" mode="date" max-date="2070-01-01" @change="change"></u-calendar>
		</view>
		<view>
			<u-calendar v-model="show3" mode="date" max-date="2070-01-01" @change="change3"></u-calendar>
		</view>
		<view>
			<u-calendar v-model="show4" mode="date" max-date="2070-01-01" @change="change4"></u-calendar>
		</view>
	</view>
</template>
<script>
	import config from '../../config.js'
	import bluetoothTool from "@/components/libs/BluetoothTool.js";
	//#ifdef APP-PLUS
	const printer = uni.requireNativePlugin('LcPrinter');
	const modal = uni.requireNativePlugin('modal');
	var globalEvent = uni.requireNativePlugin('globalEvent');
	//#endif
	export default {
		data() {
			return {
				storageNumber: '',
				goodsId: '',
				HxStoragePutDetailedParam: {},
				dataList: [],
				keyword: '',
				fromd: {},
				addNum: '',
				fromgz: {},
				frombatch: {},
				show: false,
				show3: false,
				show4: false,
				popupShow: false,
				popupShow2: false,
				popupShow3: false,
				popupShow4: false,
				printChecked: true,
				currDev: null,
				printLock: false, // 默认未加锁
			}
		},
		onLoad(open) {
			//#ifdef H5 || APP-PLUS
			this.flex = 'u-flex'
			//#endif

			this.storageNumber = open.storageNumber
			this.goodsId = open.goodsId
			//#ifdef APP-PLUS
			// 添加打印状态监听
			globalEvent.addEventListener('onPrintCallback', function(e) {
				uni.showToast({
					title: 'state: ' + JSON.stringify(e),
					duration: 2000
				});
				if (e.key == 0) {
					uni.showToast({
						title: '打印成功',
						duration: 2000
					});
				} else if (e.key == 3) {
					uni.showToast({
						title: '缺纸',
						duration: 2000
					});
				}
			});
			//打印机版本获取回调
			globalEvent.addEventListener('onVersion', function(e) {
				uni.showToast({
					title: 'version: ' + JSON.stringify(e),
					duration: 2000
				});
			});
			globalEvent.addEventListener('getsupportprint', function(e) {
				console.log('key: ' + JSON.stringify(e));
				uni.showToast({
					title: 'key: ' + JSON.stringify(e),
					duration: 2000
				});
			});
			//#endif
		},
		//#ifdef APP-PLUS
		created: function(option) {},
		onHide: function() {},
		destroyed: function() {},
		//#endif
		onShow() {
			this.refresh()
			var datalist = uni.getStorageSync('userInfo') //取出缓存数据
			this.currDev = datalist
		},
		onPullDownRefresh() {
			this.refresh()
			uni.stopPullDownRefresh()
		},
		methods: {

			deletet() {
				uni.showLoading({
					title: '加载中...'
				})
				this.$http.post('/rest/HxStoragePut/delete', {}, {
					params: {
						id: this.fromd.id,
						goodsId: this.fromd.goodsId,
						storageNumber: this.fromd.storageNumber
					},
					header: {
						'Authorization': uni.getStorageSync('token'),
					}
				}).then(res => {
					uni.hideLoading()
					if (res.data.code == 200) {
						this.$refs.uToast.show({
							title: '删除成功',
							type: 'success'
						})
						this.popupShow = false
						setTimeout(() => {
							this.refresh()
						}, 600)
					} else {
						this.$refs.uToast.show({
							title: res.data.message,
							type: 'error'
						})
						setTimeout(() => {
							this.refresh()
						}, 1000)
					}
				})
			},
			define4() {
				if (typeof this.addNum == 'undefined' || this.addNum == null || this
					.addNum == "") {
					uni.showToast({
						title: "请输入数量",
						icon: 'none'
					})
					return
				}
				uni.showLoading({
					title: '加载中...'
				})
				this.$http.post('/rest/HxStoragePut/add', {}, {
					params: {
						storageNumber: this.storageNumber,
						goodsId: this.goodsId,
						num: this.addNum,
					},
					header: {
						'Authorization': uni.getStorageSync('token'),
					}
				}).then(res => {
					uni.hideLoading()
					if (res.data.code == 200) {
						this.$refs.uToast.show({
							title: '添加成功',
							type: 'success'
						})
						this.popupShow4 = false
						setTimeout(() => {
							this.refresh()
						}, 600)
					} else {
						this.$refs.uToast.show({
							title: res.data.message,
							type: 'error'
						})
						setTimeout(() => {
							this.refresh()
						}, 1000)
					}
				})
			},
			toadd() {
				this.popupShow4 = true
			},
			imgs(fileId) {
				return config.root + 'system/previewa/' + fileId
			},
			viewImage(fileId) {
				let arr = []
				let img = config.root + 'system/previewa/' + fileId
				arr.push(img)
				uni.previewImage({
					urls: arr,
				});
			},
			define3() {
				if (typeof this.frombatch.detailedDate == 'undefined' || this.frombatch.detailedDate == null || this
					.frombatch.detailedDate == "") {
					uni.showToast({
						title: "请选择生产日期",
						icon: 'none'
					})
					return
				}

				// // 检查质保期是否过期
				//  const goodsWarranty2 = parseInt(this.frombatch.goodsWarranty, 10); // 确保质保期是整数
				//  console.log("质保期天数: " + goodsWarranty2);
				//  const productionDate2 = new Date(this.frombatch.detailedDate);
				//  const today2 = new Date();

				//  // 确保日期的时间部分设置为零
				//  productionDate2.setHours(0, 0, 0, 0);
				//  today2.setHours(0, 0, 0, 0);

				//  // 计算质保期到期日期
				//  const expiryDate2 = new Date(productionDate2);
				//  expiryDate2.setDate(productionDate2.getDate() + goodsWarranty2);
				//  console.log("生产日期: " + productionDate2.toDateString());
				//  console.log("质保期到期日期: " + expiryDate2.toDateString());
				//  console.log("今天日期: " + today2.toDateString());

				//  // 判断是否超期
				//  if (today2 > expiryDate2) {
				//   this.$refs.uToast.show({
				//   	title: "已过保质期",
				//   	type: 'error'
				//   })
				//    return;
				//  }
				uni.showLoading({
					title: '加载中...'
				})
				this.$http.post('/rest/HxStoragePut/allquality', {}, {
					params: {
						storageNumber: this.frombatch.storageNumber,
						goodsId: this.frombatch.goodsId,
						detailedDate: this.frombatch.detailedDate
					},
					header: {
						'Authorization': uni.getStorageSync('token'),
					}
				}).then(res => {
					uni.hideLoading()
					if (res.data.code == 200) {
						this.$refs.uToast.show({
							title: '质检成功',
							type: 'success'
						})
						this.popupShow3 = false
						if (this.printChecked) {
							this.$http.post('/rest/HxStoragePut/detailedSum', {}, {
								params: {
									storageNumber: this.storageNumber,
									goodsId: this.goodsId
								},
								header: {
									'Authorization': uni.getStorageSync('token'),
								}
							}).then(res => {
								uni.hideLoading()
								if (res.data.data != null && res.data.data != '') {
									this.HxStoragePutDetailedParam = res.data.data
									this.$http.post('/rest/HxStoragePut/detailedlist', {}, {
										params: {
											storageNumber: this.storageNumber,
											goodsId: this.goodsId
										},
										header: {
											'Authorization': uni.getStorageSync('token'),
										}
									}).then(res => {
										this.dataList = res.data.data
										this.printData();
									})
								}
							})
						}
					} else {
						this.$refs.uToast.show({
							title: res.data.message,
							type: 'error'
						})
						setTimeout(() => {
							this.refresh()
						}, 1000)
					}
				})
			},
			change4(e) {
				this.fromadd.detailedDate = e.result
			},
			change3(e) {
				this.frombatch.detailedDate = e.result
			},
			getT4() {
				this.show4 = true
			},
			getT3() {
				this.show3 = true
			},
			allQuality(item) {
				this.frombatch = item
				this.popupShow3 = true
			},
			editGoods(item) {
				this.fromgz = item
				this.popupShow2 = true
			},
			define2() {
				if (typeof this.fromgz.goodsBottom == 'undefined' || this.fromgz.goodsBottom == null || this.fromgz
					.goodsBottom == "") {
					uni.showToast({
						title: "请输入底",
						icon: 'none'
					})
					return
				}
				if (typeof this.fromgz.goodsLamination == 'undefined' || this.fromgz.goodsLamination == null || this.fromgz
					.goodsLamination == "") {
					uni.showToast({
						title: "请输入叠层",
						icon: 'none'
					})
					return
				}
				if (typeof this.fromgz.goodsVolume == 'undefined' || this.fromgz.goodsVolume == null || this.fromgz
					.goodsVolume == "") {
					uni.showToast({
						title: "请输入体积",
						icon: 'none'
					})
					return
				}
				if (typeof this.fromgz.goodsWeight == 'undefined' || this.fromgz.goodsWeight == null || this.fromgz
					.goodsWeight == "") {
					uni.showToast({
						title: "请输入重量",
						icon: 'none'
					})
					return
				}
				uni.showLoading({
					title: '加载中...'
				})
				this.$http.post('/rest/HxStoragePut/editGoods', {}, {
					params: {
						storageNumber: this.fromgz.storageNumber,
						goodsId: this.fromgz.goodsId,
						goodsBottom: this.fromgz.goodsBottom,
						goodsLamination: this.fromgz.goodsLamination,
						goodsVolume: this.fromgz.goodsVolume,
						goodsWeight: this.fromgz.goodsWeight,
						goodsHcode69: this.fromgz.goodsHcode69,
						goodsXcode69: this.fromgz.goodsXcode69,
					},
					header: {
						'Authorization': uni.getStorageSync('token'),
					}
				}).then(res => {
					uni.hideLoading()
					if (res.data.code == 200) {
						this.$refs.uToast.show({
							title: '修改成功',
							type: 'success'
						})
						this.popupShow2 = false
						setTimeout(() => {
							this.refresh()
						}, 600)
					} else {
						this.$refs.uToast.show({
							title: res.data.message,
							type: 'error'
						})
						setTimeout(() => {
							this.refresh()
						}, 1000)
					}
				})
			},
			change(e) {
				this.fromd.detailedDate = e.result
			},
			getT() {
				this.show = true
			},
			define() {
				if (typeof this.fromd.realNum == 'undefined' || this.fromd.realNum == null || this.fromd.realNum == "") {
					uni.showToast({
						title: "请输入实际数量",
						icon: 'none'
					})
					return
				}
				if (typeof this.fromd.detailedDate == 'undefined' || this.fromd.detailedDate == null || this.fromd
					.detailedDate == "") {
					uni.showToast({
						title: "请选择生产日期",
						icon: 'none'
					})
					return
				}
				//  // 检查质保期是否过期
				//  const goodsWarranty = parseInt(this.fromd.goodsWarranty, 10); // 确保质保期是整数
				//  console.log("质保期天数: " + goodsWarranty);
				//  const productionDate = new Date(this.fromd.detailedDate);
				//  const today = new Date();

				//  // 确保日期的时间部分设置为零
				//  productionDate.setHours(0, 0, 0, 0);
				//  today.setHours(0, 0, 0, 0);

				//  // 计算质保期到期日期
				//  const expiryDate = new Date(productionDate);
				//  expiryDate.setDate(productionDate.getDate() + goodsWarranty);
				// console.log("生产日期: " + productionDate.toDateString());
				//  console.log("质保期到期日期: " + expiryDate.toDateString());
				//  console.log("今天日期: " + today.toDateString());

				//  // 判断是否超期
				//  if (today > expiryDate) {
				//    this.$refs.uToast.show({
				//    	title: "已过保质期",
				//    	type: 'error'
				//    })
				//    return;
				//  }
				uni.showLoading({
					title: '加载中...'
				})
				this.$http.post('/rest/HxStoragePut/quality', {}, {
					params: {
						id: this.fromd.id,
						realNum: this.fromd.realNum,
						detailedDate: this.fromd.detailedDate
					},
					header: {
						'Authorization': uni.getStorageSync('token'),
					}
				}).then(res => {
					uni.hideLoading()
					if (res.data.code == 200) {
						this.$refs.uToast.show({
							title: '质检成功',
							type: 'success'
						})

						this.dataList = [];
						this.popupShow = false
						setTimeout(() => {
							this.refresh()
						}, 600)
						if (this.printChecked) {
							this.printData1(this.fromd);
							//this.printsiyue1(this.fromd)

						}
					} else {
						this.$refs.uToast.show({
							title: res.data.message,
							type: 'error'
						})
						setTimeout(() => {
							this.refresh()
						}, 1000)
					}
				})
			},
			quality(item) {
				if (item.putState == '待质检') {
					this.fromd = item
					this.fromd.realNum = this.fromd.num
					this.popupShow = true
				} else {
					uni.showModal({
						content: '确定撤销吗？',
						success: (res) => {
							if (res.confirm) {
								this.$http.post('/rest/HxStoragePut/revoke', {}, {
									params: {
										id: item.id
									},
									header: {
										'Authorization': uni.getStorageSync('token'),
									}
								}).then(res => {
									if (res.data.code == 200) {
										this.$refs.uToast.show({
											title: '撤销成功',
											type: 'success'
										})
										setTimeout(() => {
											this.refresh()
										}, 600)
									} else {
										this.$refs.uToast.show({
											title: res.data.message,
											type: 'error'
										})
										setTimeout(() => {
											this.refresh()
										}, 1000)
									}
								})
							} else if (res.cancel) {
								console.log('用户点击取消');
							}
						}
					})
				}
			},
			refresh() {
				uni.showLoading({
					title: '加载中...'
				})
				this.$http.post('/rest/HxStoragePut/detailedSum', {}, {
					params: {
						storageNumber: this.storageNumber,
						goodsId: this.goodsId
					},
					header: {
						'Authorization': uni.getStorageSync('token'),
					}
				}).then(res => {
					uni.hideLoading()
					if (res.data.data != null && res.data.data != '') {
						this.HxStoragePutDetailedParam = res.data.data
						this.$http.post('/rest/HxStoragePut/detailedlist', {}, {
							params: {
								storageNumber: this.storageNumber,
								goodsId: this.goodsId
							},
							header: {
								'Authorization': uni.getStorageSync('token'),
							}
						}).then(res => {
							this.dataList = res.data.data
							console.log("21121212", this.dataList)
						})
					}
				})
			},

			async printData1(fromd) {
				await this.printTest1(fromd);
			},

			async printLoop1() {
				// var str = "FORM " + '\r\n'; //发送给打印机，标签结束指令
				// str += "PRINT " + '\r\n';
				// console.log(str);
				var printli = bluetoothTool.sendData(str);
				try {
					let deviceId = this.currDev.deviceId;
					let serviceId = this.currDev.serviceId;
					let characteristicId = this.currDev.characteristics;

					var uint8Buf = Array.from(printli);

					function split_array(datas, size) {
						var result = {};
						var j = 0
						if (datas.length < size) {
							size = datas.length
						}
						for (var i = 0; i < datas.length; i += size) {
							result[j] = datas.slice(i, i + size)
							j++
						}
						//result[j] = datas
						console.log(result)
						return result
					}
					var sendloop = split_array(uint8Buf, 20);
					console.log(sendloop)
					async function realWriteData(sendloop, i) {
						var data = sendloop[i]
						console.log(data)
						//console.log("第【" + i + "】次写数据"+data)
						var buffer = new ArrayBuffer(data.length)
						var dataView = new DataView(buffer)
						for (var j = 0; j < data.length; j++) {
							dataView.setUint8(j, data[j]);
						}
						try {
							await uni.writeBLECharacteristicValue({
								deviceId,
								serviceId,
								characteristicId,
								value: buffer,
								success(res) {
									console.log('发送成功', i)
								},
								fail(e) {
									console.log('发送数据失败')
									console.log(e)
								}
							})
							await new Promise(resolve => setTimeout(resolve, 50));
							await realWriteData(sendloop, i + 1);
						} catch (e) {
							console.error('发送数据失败', e);
						}
					}
					var i = 0;
					await realWriteData(sendloop, i);
				} catch (error) {
					// 错误处理
					console.error(error);
				}


			},
			async printTest1(fromd) { //发送给打印机，打印内容
				if (this.printLock) {
					return; // 如果已经加锁，直接返回
				}
				this.printLock = true; // 加锁
				try {
					let deviceId = this.currDev.deviceId;
					let serviceId = this.currDev.serviceId;
					let characteristicId = this.currDev.characteristics;


					console.log(fromd)
					var str = '';
					str += 'SIZE 40 mm,70 mm\r\n';
					str += 'GAP 2 mm\r\n';
					str += 'CLS\r\n';
					str += 'TEXT 50,20,"TSS24.BF2",0,1,1,"' + fromd.goodsName + '"\r\n';
					str += 'TEXT 50,70,"TSS24.BF2",0,2,2,"' + fromd.trayNumber + '"\r\n';
					str += 'TEXT 50,120,"TSS24.BF2",0,2,2,"数量:' + fromd.realNum + '"\r\n';
					str += 'TEXT 50,170,"TSS24.BF2",0,1,1,"规格:' + fromd.goodsSpecs + '"\r\n';
					str += 'TEXT 50,220,"TSS24.BF2",0,2,2,"' + fromd.detailedDate + '"\r\n';
					str += 'TEXT 50,270,"TSS24.BF2",0,2,2,"' + fromd.positionNumberYes + '"\r\n';

					str += 'QRCODE 120,320,H,8,A,0,"' + fromd.trayNumber + '"\r\n';

					str += 'PRINT 1\r\n';
					// 标签开始, 固定开头, 详见 指令集文档
					// var str = " ! 0 200 200 210 1 " + '\r\n';
					// str += "CENTER" + '\r\n';
					// // 设置打印纸张宽度
					// str += "PAGE-WIDTH 600" + '\r\n';

					// // 标签内容
					// // 文本 {command} {font} {size} {x} {y} {data}
					// // 二维码 {command} {type} {x} {y} [M n] [U n] {data}
					// str += "B QR 380 120 M 3 U 7" + '\r\n';
					// str += "MA," + fromd.trayNumber + "\r\n";
					// str += "ENDQR" + '\r\n';

					// // str += "RIGHT" + '\r\n';
					// str += "SETMAG 2 2" + '\r\n';
					// str += "TEXT 4 0 220 320  " + fromd.trayNumber + "\r\n";
					// str += "SETMAG 1 1" + '\r\n';
					// str += "LEFT" + '\r\n';
					// str += "SETMAG 2 2" + '\r\n';

					// str += "TEXT 4 0 20 20  " + fromd.goodsName + "\r\n";
					// str += "TEXT 30 10 20 100  数量:" + this.fromd.realNum + "\r\n";
					// str += "SETMAG 1 1" + '\r\n';
					// str += "TEXT 4 0 20 150  规格:" + fromd.goodsSpecs + "\r\n";
					// str += "TEXT 4 0 20 200  生产日期:" + fromd.detailedDate + "\r\n";
					// str += "TEXT 4 0 20 250  编号:" + fromd.goodsNumber + "\r\n";
					// str += "TEXT 4 0 20 300  商品码:" + fromd.goodsPcode69 + "\r\n";
					// str += "TEXT 4 0 20 350 配送单位:" + fromd.unit + "\r\n";

					// console.log(str)
					var printli = bluetoothTool.sendData(str);

					console.log('************deviceId = [' + deviceId + ']  serviceId = [' + serviceId +
						'] characteristics=[' + characteristicId + "]")
					var uint8Buf = Array.from(printli);

					function split_array(datas, size) {
						var result = {};
						var j = 0
						if (datas.length < size) {
							size = datas.length
						}
						for (var i = 0; i < datas.length; i += size) {
							result[j] = datas.slice(i, i + size)
							j++
						}
						//result[j] = datas
						console.log(result)
						return result
					}
					var sendloop = split_array(uint8Buf, 20);
					console.log(sendloop)
					async function realWriteData(sendloop, i) {
						var data = sendloop[i]
						console.log(data)
						//console.log("第【" + i + "】次写数据"+data)
						var buffer = new ArrayBuffer(data.length)
						var dataView = new DataView(buffer)
						for (var j = 0; j < data.length; j++) {
							dataView.setUint8(j, data[j]);
						}
						try {
							await uni.writeBLECharacteristicValue({
								deviceId,
								serviceId,
								characteristicId,
								value: buffer,
								success(res) {
									console.log('发送成功', i)
								},
								fail(e) {
									console.log('发送数据失败')
									console.log(e)
								}
							})
							await new Promise(resolve => setTimeout(resolve, 50));
							await realWriteData(sendloop, i + 1);

						} catch (e) {
							console.error('发送数据失败', e);
						}
					}
					var i = 0;
					await realWriteData(sendloop, i);
					await new Promise(resolve => setTimeout(resolve, 50));
				} catch (error) {
					// 错误处理
					console.error(error);
					// 解锁
				} finally {
					this.printLock = false;

					this.printLoop1();

				}

			},
			async printData() {
				console.log("printData", this.dataList)
				for (var j = 0; j < this.dataList.length; j++) {
					const data = this.dataList[j];
					console.log(data)
					await this.printTest(data);
				}
			},
			async printLoop() {
				// var str = "FORM " + '\r\n'; //发送给打印机，标签结束指令
				// str += "PRINT " + '\r\n';
				// console.log(str);
				var printli = bluetoothTool.sendData(str);
				try {
					let deviceId = this.currDev.deviceId;
					let serviceId = this.currDev.serviceId;
					let characteristicId = this.currDev.characteristics;

					var uint8Buf = Array.from(printli);

					function split_array(datas, size) {
						var result = {};
						var j = 0
						if (datas.length < size) {
							size = datas.length
						}
						for (var i = 0; i < datas.length; i += size) {
							result[j] = datas.slice(i, i + size)
							j++
						}
						//result[j] = datas
						console.log(result)
						return result
					}
					var sendloop = split_array(uint8Buf, 20);
					console.log(sendloop)
					async function realWriteData(sendloop, i) {
						var data = sendloop[i]
						console.log(data)
						//console.log("第【" + i + "】次写数据"+data)
						var buffer = new ArrayBuffer(data.length)
						var dataView = new DataView(buffer)
						for (var j = 0; j < data.length; j++) {
							dataView.setUint8(j, data[j]);
						}
						try {
							await uni.writeBLECharacteristicValue({
								deviceId,
								serviceId,
								characteristicId,
								value: buffer,
								success(res) {
									console.log('发送成功', i)
								},
								fail(e) {
									console.log('发送数据失败')
									console.log(e)
								}
							})
							await new Promise(resolve => setTimeout(resolve, 50));
							await realWriteData(sendloop, i + 1);
						} catch (e) {
							console.error('发送数据失败', e);
						}
					}
					var i = 0;
					await realWriteData(sendloop, i);
				} catch (error) {
					// 错误处理
					console.error(error);
				}


			},
			async printTest(data) { //发送给打印机，打印内容
				if (this.printLock) {
					return; // 如果已经加锁，直接返回
				}
				this.printLock = true; // 加锁
				try {
					let deviceId = this.currDev.deviceId;
					let serviceId = this.currDev.serviceId;
					let characteristicId = this.currDev.characteristics;

					const data1 = this.HxStoragePutDetailedParam
					console.log(data)



					var str = '';
					str += 'SIZE 40 mm,70 mm\r\n';
					str += 'GAP 2 mm\r\n';
					str += 'CLS\r\n';

					str += 'TEXT 50,20,"TSS24.BF2",0,1,1,"' + data.goodsName + '"\r\n';
					str += 'TEXT 50,70,"TSS24.BF2",0,2,2,"' + data.trayNumber + '"\r\n';
					str += 'TEXT 50,120,"TSS24.BF2",0,2,2,"数量:' + data.realNum + '"\r\n';
					str += 'TEXT 50,170,"TSS24.BF2",0,1,1,"规格:' + data.goodsSpecs + '"\r\n';
					str += 'TEXT 50,220,"TSS24.BF2",0,2,2,"' + data.detailedDate + '"\r\n';
					str += 'TEXT 50,270,"TSS24.BF2",0,2,2,"' + data.positionNumberYes + '"\r\n';

					str += 'QRCODE 120,320,H,8,A,0,"' + data.trayNumber + '"\r\n';

					str += 'PRINT 1\r\n';
					// 标签开始, 固定开头, 详见 指令集文档
					// var str = " ! 0 200 200 210 1 " + '\r\n';
					// str += "CENTER" + '\r\n';
					// // 设置打印纸张宽度
					// str += "PAGE-WIDTH 600" + '\r\n';

					// // 标签内容
					// // 文本 {command} {font} {size} {x} {y} {data}
					// // 二维码 {command} {type} {x} {y} [M n] [U n] {data}
					// str += "B QR 380 120 M 3 U 7" + '\r\n';
					// str += "MA," + data.trayNumber + "\r\n";
					// str += "ENDQR" + '\r\n';

					// // str += "RIGHT" + '\r\n';
					// str += "SETMAG 2 2" + '\r\n';
					// str += "TEXT 4 0 220 320  " + data.trayNumber + "\r\n";
					// str += "SETMAG 1 1" + '\r\n';
					// str += "LEFT" + '\r\n';
					// str += "SETMAG 2 2" + '\r\n';

					// str += "TEXT 4 0 20 20  " + data.goodsName + "\r\n";
					// str += "TEXT 30 10 20 100  数量:" + data.realNum + "\r\n";
					// str += "SETMAG 1 1" + '\r\n';
					// str += "TEXT 4 0 20 150  规格:" + data.goodsSpecs + "\r\n";
					// str += "TEXT 4 0 20 200  生产日期:" + data.detailedDate + "\r\n";
					// str += "TEXT 4 0 20 250  编号:" + data.goodsNumber + "\r\n";
					// str += "TEXT 4 0 20 300  商品码:" + data.goodsPcode69 + "\r\n";
					// str += "TEXT 4 0 20 350 配送单位:" + data.unit + "\r\n";
					console.log(str)
					var printli = bluetoothTool.sendData(str);

					console.log('************deviceId = [' + deviceId + ']  serviceId = [' + serviceId +
						'] characteristics=[' + characteristicId + "]")
					var uint8Buf = Array.from(printli);

					function split_array(datas, size) {
						var result = {};
						var j = 0
						if (datas.length < size) {
							size = datas.length
						}
						for (var i = 0; i < datas.length; i += size) {
							result[j] = datas.slice(i, i + size)
							j++
						}
						//result[j] = datas
						console.log(result)
						return result
					}
					var sendloop = split_array(uint8Buf, 20);
					console.log(sendloop)
					async function realWriteData(sendloop, i) {
						var data = sendloop[i]
						console.log(data)
						//console.log("第【" + i + "】次写数据"+data)
						var buffer = new ArrayBuffer(data.length)
						var dataView = new DataView(buffer)
						for (var j = 0; j < data.length; j++) {
							dataView.setUint8(j, data[j]);
						}
						try {
							await uni.writeBLECharacteristicValue({
								deviceId,
								serviceId,
								characteristicId,
								value: buffer,
								success(res) {
									console.log('发送成功', i)
								},
								fail(e) {
									console.log('发送数据失败')
									console.log(e)
								}
							})
							await new Promise(resolve => setTimeout(resolve, 50));
							await realWriteData(sendloop, i + 1);

						} catch (e) {
							console.error('发送数据失败', e);
						}
					}
					var i = 0;
					await realWriteData(sendloop, i);
					await new Promise(resolve => setTimeout(resolve, 50));


				} catch (error) {
					// 错误处理
					console.error(error);
					// 解锁
				} finally {
					this.printLock = false;

					this.printLoop();

				}

			},

			//#ifdef APP-PLUS
			async printsiyue1(fromd) {
				await this.printerLabel1(fromd);
			},

			async printsiyue() {

				for (var j = 0; j < this.dataList.length; j++) {
					const data = this.dataList[j];
					await this.printerLabel(data);
				}

			},
			initPrinter() {
				// 调用异步方法
				console.log('初始化');
				var ret = printer.initPrinter({});
				modal.toast({
					message: ret,
					duration: 0
				});
				printer.printEnableMark({
					enable: false
				});
				printer.setConcentration({ //设置打印浓度。font_level 取值范围：1~39。
					level: 39
				});
				printer.setLineSpacing({
					spacing: 1
				});
				printer.getsupportprint();
			},
			closePrinter() {
				// 调用同步方法
				console.log('关闭');
				printer.closePrinter();
			},
			printerLabel(data) {
				this.initPrinter();
				console.log('测试打印');

				printer.setFontSize({ //设置字体大小
					fontSize: 0
				});
				printer.setTextBold({ //设置字体是否加粗
					bold: true
				});
				printer.printText({
					content: "" + data.goodsName + ""
				});
				printer.printLine({ //走纸 1 行
					line_length: 1
				});
				printer.printText({
					content: "规格" + data.goodsSpecs + ""
				});
				printer.printLine({ //走纸 1 行
					line_length: 1
				});
				printer.printText({
					content: "日期" + data.detailedDate + ""
				});
				printer.printLine({ //走纸 1 行
					line_length: 1
				});
				printer.printText({
					content: "配送单位" + data.unit + ""
				});
				printer.printLine({ //走纸 1 行
					line_length: 1
				});

				printer.printText({
					content: "商品编号" + data.goodsNumber + ""
				});
				printer.printLine({ //走纸 1 行
					line_length: 1
				});
				printer.printText({
					content: "商品码" + data.goodsPcode69 + ""
				});
				printer.printLine({ //走纸 1 行
					line_length: 1
				});
				console.log('测试打印QR');
				printer.printQR({
					text: "" + data.trayNumber + "\r\n",
					height: 400,
					offset: 1
				});
				printer.printLine({ //走纸 1 行
					line_length: 2
				});

				printer.start();
				console.log('测试打印QR结束');
			},

			printerLabel1(fromd) {
				this.initPrinter();
				console.log('测试打印');

				printer.setFontSize({ //设置字体大小
					fontSize: 0
				});
				printer.setTextBold({ //设置字体是否加粗
					bold: true
				});
				printer.printText({
					content: "" + fromd.goodsName + ""
				});
				printer.printLine({ //走纸 1 行
					line_length: 1
				});
				printer.printText({
					content: "规格" + fromd.goodsSpecs + ""
				});
				printer.printLine({ //走纸 1 行
					line_length: 1
				});
				printer.printText({
					content: "日期" + fromd.detailedDate + ""
				});
				printer.printLine({ //走纸 1 行
					line_length: 1
				});
				printer.printText({
					content: "配送单位" + fromd.unit + ""
				});
				printer.printLine({ //走纸 1 行
					line_length: 1
				});

				printer.printText({
					content: "商品编号" + fromd.goodsNumber + ""
				});
				printer.printLine({ //走纸 1 行
					line_length: 1
				});
				printer.printText({
					content: "商品码" + fromd.goodsPcode69 + ""
				});
				printer.printLine({ //走纸 1 行
					line_length: 1
				});
				console.log('测试打印QR');
				printer.printQR({
					text: "" + fromd.trayNumber + "\r\n",
					height: 400,
					offset: 1
				});
				printer.printLine({ //走纸 1 行
					line_length: 2
				});

				printer.start();
				console.log('测试打印QR结束');
			},
			//#endif

		},
		// 判断是否是新品
		computed: {
			isNewProduct() {
				const createTime = new Date(this.HxStoragePutDetailedParam.createTime);
				const today = new Date();
				const sevenDaysAgo = new Date();
				sevenDaysAgo.setDate(today.getDate() - 7);

				// 判断 createTime 是否在过去 7 天内
				return createTime >= sevenDaysAgo && createTime <= today;
			}
		}

	}
</script>
<style lang="scss">
	.huanhang {
		word-break: break-all;
	}

	.jiange {
		border-bottom: 1px solid #e1e1e1;
	}

	.new-product {
		color: #ff0000;
		/* 红色 */
		font-weight: bold;
		/* 粗体 */
	}
</style>